//
//  UITextField+WJ.m
//  BeDeJie
//
//  Created by jerry on 2017/1/28.
//  Copyright © 2017年 jerry. All rights reserved.
//

#import "UITextField+WJ.h"
#import <objc/message.h>

@implementation UITextField (WJ)

+ (void)load{
    // setPlaceholder
    Method setPlaceholderMethod = class_getInstanceMethod(self, @selector(setPlaceholder:));
    Method setWj_PlaceholderMethod = class_getInstanceMethod(self, @selector(setWj_Placeholder:));
    
    method_exchangeImplementations(setPlaceholderMethod, setWj_PlaceholderMethod);
}

- (void)setPlaceholderColor:(UIColor *)placeholderColor {
    
    // 给成员属性赋值 runtime给系统的类添加成员属性
    // 添加成员属性
    objc_setAssociatedObject(self, @"placeholderColor", placeholderColor, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
    
    // 获取占位文字label控件
    UILabel *placeholderLabel = [self valueForKey:@"placeholderLabel"];
    
    // 设置占位文字颜色
    placeholderLabel.textColor = placeholderColor;
}


- (UIColor *)placeholderColor {
    return objc_getAssociatedObject(self, @"placeholderColor");
}

- (void)setWj_Placeholder:(NSString *)placeholder {
    // 设置占位文字
    [self setWj_Placeholder:placeholder];
    // 设置占位文字颜色
    self.placeholderColor = self.placeholderColor;
}

@end

